package com.lzx.utils;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: 如寄
 * @version: v1.0
 * @description: com.lzx.utils
 * @date:2021/8/14
 */
public class GetMap {
    /**
     * 将新闻内容进行处理
     *
     * @param content :新闻内容
     * @return : 经处理的新闻向量
     * @throws IOException
     */
    private TermUtils termUtils = new TermUtils();

    public Map<Integer, Boolean> toMap(String content, Map<String, Integer> feathers, List<String> featherList) throws IOException {
        Map<Integer, Boolean> map = new HashMap<>(32);
        List<String> list = termUtils.RemoveOfStopWord(content);
        for (String S : list) {
            if (feathers.containsKey(S)) {
                map.put(feathers.get(S), true);
            } else {
                featherList.add(S);
                feathers.put(S, featherList.size() - 1);
                map.put(featherList.size(), true);
            }

        }
        return map;
    }

    public Map<String, Boolean> toMap(String content) throws IOException {
        Map<String, Boolean> map = new HashMap<>(32);
        List<String> list = termUtils.RemoveOfStopWord(content);
        for (String S : list) {
            map.put(S, true);
        }
        return map;
    }
}
